home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 106_01.zip / CHARFUN.ASM < prev    next >
Assembly Source File  |  1993-06-26  |  3KB  |  165 lines

  1. ;                charfun.asm
  2. ;
  3. ;    Copyright (C) 1980, M J Maney
  4. ;
  5. ;    First created 8/16/80
  6. ;    Last revised 8/28/80 14:45
  7. ;
  8. ;    Tested and installed 8/28/80 14:55
  9. ;
  10. ;    This file contains the definitions for some character
  11. ;    functions, written in assembler for compacteness and performance.
  12. ;    The macros from the "crl.lib" file are used to create these
  13. ;    functions in the BDS "crl" format with minimum pain.
  14. ;
  15.     maclib    crl
  16. ;
  17. ;
  18. BLANK    equ    20H
  19. TAB    equ    09H
  20. NEWLINE    equ    0AH
  21. ;
  22. ;
  23. ; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  24. ;
  25. ;        functions that operate on a byte and return
  26. ;            a small integer or a character
  27. ;
  28. ;    isalpha        isupper        islower        isdigit
  29. ;    isspace        toupper        tolower
  30. ;
  31. ;        functions that operate on a pair of bytes and
  32. ;            return an integer
  33. ;
  34. ;    atob
  35. ;
  36. ; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  37. ;
  38. ;
  39.     PROC    ISALPHA
  40.     lda    ARG1
  41.     lxi    h,0
  42.     cpi    'A'
  43.     rc            ;less than 'A'
  44.     cpi    'z'+1
  45.     rnc            ;greater than 'z'
  46.     inx    h
  47.     cpi    'a'
  48.     rnc            ;lower-case alpha, return TRUE
  49.     cpi    'Z'+1
  50.     rc            ;upper-case alpha, return TRUE
  51.     dcx    h
  52.     ret            ;else return FALSE
  53.     PEND    ISALPHA
  54. ;
  55. ;
  56.     PROC    ISUPPER
  57.     lda    ARG1
  58.     lxi    h,0
  59.     cpi    'A'
  60.     rc            ;less than 'A'
  61.     cpi    'Z'+1
  62.     rnc            ;greater than 'Z'
  63.     inx    h
  64.     ret            ;else is upper-case
  65.     PEND    ISUPPER
  66. ;
  67. ;
  68.     PROC    ISLOWER
  69.     lda    ARG1
  70.     lxi    h,0
  71.     cpi    'a'
  72.     rc            ;less than 'a'
  73.     cpi    'z'+1
  74.     rnc            ;greater than 'z'
  75.     inx    h
  76.     ret            ;else is lower case
  77.     PEND    ISLOWER
  78. ;
  79. ;
  80.     PROC    ISDIGIT
  81.     lda    ARG1
  82.     lxi    h,0
  83.     cpi    '0'
  84.     rc            ;less than '0'
  85.     cpi    '9'+1
  86.     rnc            ;greater than '9'
  87.     inx    h
  88.     ret            ;else is decimal digit
  89.     PEND    ISDIGIT
  90. ;
  91. ;
  92.     PROC    ISSPACE
  93.     lda    ARG1
  94.     lxi    h,1
  95.     cpi    BLANK
  96.     rz            ;equals ' '
  97.     cpi    TAB
  98.     rz            ;equals tab
  99.     cpi    NEWLINE
  100.     rz            ;equals newline
  101.     dcx    h
  102.     ret            ;else is non-space
  103.     PEND    ISSPACE
  104. ;
  105. ;
  106.     PROC    TOUPPER
  107.     lda    ARG1
  108.     mov    l,a
  109.     mvi    h,0        ;setup to return character unchanged
  110.     cpi    'a'
  111.     rc            ;less than 'a'
  112.     cpi    'z'+1
  113.     rnc            ;greater than 'z'
  114.     adi    'A'-'a'        ;else is lower-case, convert it
  115.     mov    l,a
  116.     ret
  117.     PEND    TOUPPER
  118. ;
  119. ;
  120.     PROC    TOLOWER
  121.     lda    ARG1
  122.     mov    l,a
  123.     mvi    h,0        ;setup to return character unchanged
  124.     cpi    'A'
  125.     rc            ;less than 'A'
  126.     cpi    'Z'+1
  127.     rnc            ;greater than 'Z'
  128.     adi    'a'-'A'        ;else is upper-case, convert it
  129.     mov    l,a
  130.     ret
  131.     PEND    TOLOWER
  132. ;
  133. ;
  134.     PROC    ATOB
  135.     lda    ARG1
  136.     sbi    '0'
  137.     BC    nogood        ;illegal char below '0'
  138.     cpi    10
  139.     BC    gotit        ;character between '0' and '9'
  140.     sbi    'A' - '0'
  141.     BC    nogood        ;illegal char between '9' and 'A'
  142.     cpi    26
  143.     BC    gotalph        ;character between 'A' and 'Z'
  144.     sbi    'a' - 'A'
  145.     BC    nogood        ;illegal char between 'Z' and 'a'
  146.     cpi    26
  147.     BNC    nogood        ;illegal char above 'z'
  148. gotalph:;have valid alpha, must be offset by 10
  149.     adi    10
  150. gotit:    ;have valid alpha-numeric char, converted value in A
  151.     lxi    h,ARG2
  152.     cmp    m
  153.     BNC    nogood        ;illegal char for specified base
  154.     mov    l,a
  155.     mvi    h,0
  156.     ret
  157. ;
  158. nogood:    ;illegal character or out of range for specified base
  159.     lxi    h,-1
  160.     ret
  161.     PEND    ATOB
  162. ;
  163. ;
  164.     end
  165.